home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / tjgold.zip / INSTALL.001 / GOLD.ASM < prev    next >
Assembly Source File  |  1995-05-29  |  40KB  |  1,724 lines

  1. ;                          Copyright 1995 TJ Software
  2. ;                             All Rights Reserved           
  3. ;                            Restricted by License          
  4.  
  5. ;                                  Version 1.0
  6.  
  7. ;                           *****  GOLD.ASM  *****  
  8. ;                      Assembly procedures for TTT Gold
  9.  
  10. ; A collaborative effort by Charley Martin and Bob "Torqemada" Ainsbury
  11.  
  12.  
  13. ;--------  PROGRAM DATA STRUCTURES  ---------
  14.  
  15.  
  16. ; WinList Structure:  Doubly-linked structure of Window parms:
  17.  
  18. ; Parm    Offset    Type      Definition
  19.  
  20. ; Buffer     0      Dword     Points to Window data
  21. ; Width      4      Byte      Window width
  22. ; Depth      5      Byte      Window depth
  23. ; X          6      Byte      X coord of Window on Screen plane
  24. ; Y          7      Byte      Y coord of Window on Screen plane
  25. ; NextEntry  8      Dword     Pointer to next structure (NULL if this is last)
  26. ; .
  27. ; .
  28. ; .
  29.  
  30.  
  31. ; Equates for WinWrite, WinPlain:
  32.  
  33. WWIgnore  EQU  BYTE PTR [BP+6]     ;Ignore ShowNow
  34. WWStr     EQU  DWORD PTR [BP+8]    ;Reset by 2
  35. WWStrSeg  EQU  WORD PTR [BP+10]
  36. WWAttr    EQU  BYTE PTR [BP+12]
  37. WWY3      EQU  BYTE PTR [BP+14]
  38. WWX3      EQU  BYTE PTR [BP+16]
  39. WWY2      EQU  BYTE PTR [BP+18]
  40. WWX2      EQU  BYTE PTR [BP+20]
  41. WWY1      EQU  BYTE PTR [BP+22]
  42. WWX1      EQU  BYTE PTR [BP+24]
  43. WWWidth   EQU  BYTE PTR [BP+26]
  44. WWBuffer  EQU  DWORD PTR [BP+28]
  45. WWBuffOff EQU  WORD PTR [BP+28]    ;Assumes segment gets pushed first
  46. WWBuffSeg EQU  WORD PTR [BP+30]
  47. WWAdjust  EQU  26   ;Stack adjustment on return from WinWrite, WinPlain
  48.  
  49.  
  50. ; Equates for WinAttr:
  51.  
  52. WAIgnore  EQU  BYTE PTR [BP+6]     ;Ignore ShowNow
  53. WAAttr    EQU  BYTE PTR [BP+8]     ;All adjusted by 2
  54. WAY4      EQU  BYTE PTR [BP+10]
  55. WAX4      EQU  BYTE PTR [BP+12]
  56. WAY3      EQU  BYTE PTR [BP+14]
  57. WAX3      EQU  BYTE PTR [BP+16] ;X3,Y3 and X4,Y4 define pane in area, relative
  58. WAY2      EQU  BYTE PTR [BP+18] ;to edges of area
  59. WAX2      EQU  BYTE PTR [BP+20]
  60. WAY1      EQU  BYTE PTR [BP+22]
  61. WAX1      EQU  BYTE PTR [BP+24] ;X1,Y1 and X2,Y2 define area within window,
  62. WAWidth   EQU  BYTE PTR [BP+26] ;relative to window edges
  63. WABuffer  EQU  DWORD PTR [BP+28]
  64. WABuffOff EQU  WORD PTR [BP+28]
  65. WABuffSeg EQU  WORD PTR [BP+30]
  66. WAAdjust  EQU  26   ;Stack adjustment
  67.  
  68.  
  69. ; Equates for FillVideo:
  70.  
  71. FVData    EQU  WORD PTR [BP+6]
  72. FVLen     EQU  WORD PTR [BP+8]
  73. FVBuffer  EQU  DWORD PTR [BP+10]
  74. FVAdjust  EQU  8    ;Stack adjustment
  75.  
  76.  
  77. ; Equates for WinRedraw:
  78.  
  79. WRShow    EQU  BYTE PTR [BP+6]
  80. WRAdjust  EQU  2
  81.  
  82.  
  83. ; Equates for MoveFromScreen
  84.  
  85. MFTarget       EQU  DWORD PTR [BP+6]     
  86. MFSource       EQU  DWORD PTR [BP+10]   ;Added 7/7/93 on request
  87. MFSourceOff    EQU  WORD PTR [BP+10]    ;Extra definition
  88. MFSourceSeg    EQU  WORD PTR [BP+12]    ;  "
  89. MFSWidth       EQU  BYTE PTR [BP+14]    ;Added 7/7/93
  90. MFY2           EQU  BYTE PTR [BP+16]     
  91. MFX2           EQU  BYTE PTR [BP+18]
  92. MFY1           EQU  BYTE PTR [BP+20]
  93. MFX1           EQU  BYTE PTR [BP+22]
  94. MFAdjust       EQU  18   ;Stack adjustment on far return
  95.  
  96.  
  97. ; Equates for MoveToScreen
  98.  
  99. MTTarget       EQU  DWORD PTR [BP+6] ;pointer to target buffer
  100. MTTargetOff    EQU  WORD PTR [BP+6]  ;Extra
  101. MTTargetSeg    EQU  WORD PTR [BP+8]  ;Extra
  102. MTTWidth       EQU  BYTE PTR [BP+10] ;width of target screen
  103. MTTY3          EQU  BYTE PTR [BP+12] ;upper-left corner of target
  104. MTTX3          EQU  BYTE PTR [BP+14] ;upper-left corner of target
  105. MTSource       EQU  DWORD PTR [BP+16];pointer to source buffer
  106. MTSourceOff    EQU  WORD PTR [BP+16] ;Extra
  107. MTSourceSeg    EQU  WORD PTR [BP+18] ;Extra
  108. MTSWidth       EQU  BYTE PTR [BP+20] ;width of source screen
  109. MTSY2          EQU  BYTE PTR [BP+22] ;lower-rght corner of source
  110. MTSX2          EQU  BYTE PTR [BP+24] ;lower-rght corner of source
  111. MTSY1          EQU  BYTE PTR [BP+26] ;upper-left corner of source
  112. MTSX1          EQU  BYTE PTR [BP+28] ;upper-left corner of source
  113. MTAdjust       EQU  24  ;Stack adjustment on far return
  114.  
  115. ; Equates for Different
  116.  
  117. MCSource       EQU  DWORD PTR [BP+6]  ;pointer to source buffer
  118. MCTarget       EQU  DWORD PTR [BP+10] ;pointer to target buffer
  119. MCByteCount    EQU  WORD PTR [BP+14]  ;number of bytes to compare
  120. MCByteCount    EQU  WORD PTR [BP+6]   ;number of bytes to compare
  121. MCTarget       EQU  DWORD PTR [BP+8]  ;pointer to target buffer
  122. MCSource       EQU  DWORD PTR [BP+12] ;pointer to source buffer
  123. MCAdjust       EQU  10
  124.  
  125.  
  126. ; ------------ GLOBAL DATA ----------------
  127.  
  128.  SEGMENT  DATA byte public
  129.  
  130.  EXTRN    SnowProne      : BYTE
  131.  EXTRN    LineWrap       : BYTE
  132.  EXTRN    ShowNow        : BYTE
  133.  EXTRN    ScreenLines    : BYTE
  134.  EXTRN    WinList        : DWORD
  135.  EXTRN    BackBuffer     : DWORD
  136.  EXTRN    FrontBuffer    : DWORD   ;Pointer to Video work area
  137.  
  138. ; *****  THESE DECLARATIONS MUST BE ADDED TO THE DATA AREA  *****
  139.  
  140.  EXTRN    WinX           : BYTE
  141.  EXTRN    WinY           : BYTE
  142.  EXTRN    WinWidth0      : WORD
  143.  EXTRN    WinWidth       : WORD
  144.  EXTRN    WinDepth0      : WORD
  145.  EXTRN    WinDepth       : WORD
  146.  EXTRN    WinOff         : WORD
  147.  EXTRN    SourceIncr     : WORD
  148.  EXTRN    TargetIncr     : WORD
  149.  EXTRN    ShadowAttr     : BYTE
  150.  EXTRN    ShadowType     : BYTE    ;4=no shadow
  151.  EXTRN    PaneType       : BYTE
  152.  EXTRN    CRFlag         : BYTE
  153.  EXTRN    PaneWidth      : WORD
  154.  EXTRN    PaneDepth      : WORD
  155.  EXTRN    PaneOff        : WORD
  156.  EXTRN    WriteDepth     : BYTE
  157.  EXTRN    SegB000        : WORD
  158.  EXTRN    SegB800        : WORD
  159.  EXTRN    BBTop          : BYTE
  160.  EXTRN    BBBot          : BYTE
  161.  
  162.  
  163.  ENDS     DATA
  164.  
  165.  
  166.  SEGMENT CODE byte public
  167.  
  168.  
  169.  ASSUME  CS:CODE, DS:DATA
  170.  
  171.  
  172.  PUBLIC  WinWrite, WinPlain, WinAttr, WinRedraw, FillVideo, TopWinRedraw
  173.  PUBLIC  MoveToScreen, MoveFromScreen, Different, A@@@@@@@@@
  174.  
  175.  
  176. ;-------- PROGRAM CODE AREA --------
  177.  
  178.  
  179. ;------------------
  180. MoveFromScreen proc far
  181. ;    MoveFromScreen moves part of the screen (character and attr)
  182. ;    from the visible screen to a buffer.  Target is a contiguous array
  183. ;    Source far pointer and width are passed, and NOT assumed to be 
  184. ;    visible screen
  185.  
  186.  cld
  187.  push     bp        ;Save base pointer
  188.  mov      bp,sp     ;Set up stack frame
  189.  
  190.  mov      al,MFSWidth    ;Calculate Source increment
  191.  xor      ah,ah
  192.  shl      ax,1
  193.  mov      [SourceIncr],ax
  194.  
  195.  mov      al,MFY1   ;calculate offset in video memory
  196.  dec      al
  197.  mov      bl,MFSWidth
  198.  mul      bl
  199.  add      al,MFX1
  200.  adc      ah,0
  201.  dec      ax
  202.  shl      ax,1
  203.  mov      si,ax
  204.  add      si,MFSourceOff
  205.  
  206.  mov      cl,MFY2   ;How many rows? Hold in cx
  207.  sub      cl,MFY1
  208.  inc      cl
  209.  xor      ch,ch
  210.  
  211.  mov      bl,MFX2   ;How many chars wide? Hold in bx
  212.  sub      bl,MFX1
  213.  inc      bl
  214.  xor      bh,bh
  215.  
  216.  les      di,MFTarget
  217.  
  218. MFS_Loop:
  219.  push     cx
  220.  push     si
  221.  mov      cx,bx
  222.  
  223.  push     ds
  224.  mov      ds,MFSourceSeg
  225.  rep      movsw
  226.  pop      ds
  227.  
  228.  pop      si
  229.  pop      cx
  230.  add      si,[SourceIncr]
  231.  loop     MFS_Loop
  232.  
  233.  pop      bp
  234.  
  235.  ret      MFAdjust
  236.  
  237. MoveFromScreen endp
  238.  
  239.  
  240. ;------------------
  241. MoveToScreen   proc far
  242. ;    MoveToScreen moves part (or all) of a virtual screen to part of
  243. ;    another virtual screen, or the visible screen. If the target is the
  244. ;    visible screen, snow checking should be performed.
  245. ;    No checking is done for negative values of coords
  246.  
  247.  cld
  248.  push     bp        ;Save base pointer
  249.  mov      bp,sp     ;Set up stack frame
  250.  
  251.  cmp      [SnowProne],0
  252.  je       MTS_0
  253.  call     GetVidSeg
  254.  cmp      dx,MTTargetSeg
  255.  jne      MTS_0
  256.  call     VerticalPause
  257.  
  258. MTS_0:
  259.  mov      al,MTSWidth
  260.  xor      ah,ah
  261.  shl      ax,1
  262.  mov      [SourceIncr],ax
  263.  
  264.  mov      al,MTTWidth
  265.  xor      ah,ah
  266.  shl      ax,1
  267.  mov      [TargetIncr],ax
  268.  
  269.  mov      al,MTSY2
  270.  sub      al,MTSY1
  271.  inc      al
  272.  xor      ah,ah
  273.  mov      [PaneDepth],ax
  274.  
  275.  mov      al,MTSX2
  276.  sub      al,MTSX1
  277.  inc      al
  278.  xor      ah,ah
  279.  mov      [PaneWidth],ax
  280.  
  281.  mov      al,MTSY1
  282.  dec      al
  283.  mov      bl,MTSWidth
  284.  mul      bl
  285.  add      al,MTSX1
  286.  adc      ah,0
  287.  dec      ax
  288.  shl      ax,1
  289.  mov      si,ax
  290.  
  291.  mov      al,MTTY3
  292.  dec      al
  293.  mov      bl,MTTWidth
  294.  mul      bl
  295.  add      al,MTTX3
  296.  adc      ah,0
  297.  dec      ax
  298.  shl      ax,1
  299.  mov      di,ax
  300.  
  301.  add      si,MTSourceOff
  302.  add      di,MTTargetOff
  303.  
  304.  mov      es,MTTargetSeg
  305.  
  306.  mov      cx,[PaneDepth]
  307.  
  308. MTS_loop:
  309.  push     cx
  310.  push     si
  311.  push     di
  312.  
  313.  mov      cx,[PaneWidth]
  314.  
  315.  push     ds
  316.  mov      ds,MTSourceSeg
  317.  rep      movsw
  318.  pop      ds
  319.  
  320.  pop      di
  321.  pop      si
  322.  pop      cx
  323.  add      si,[SourceIncr]
  324.  add      di,[TargetIncr]
  325.  loop     MTS_loop
  326.  
  327.  pop      bp
  328.  
  329.  ret      MTAdjust
  330.  
  331. MoveToScreen   endp
  332.  
  333.  
  334. ;------------------
  335. WinWrite  proc far
  336.  
  337. ; Passes cursor coords back through ax -- see PaneWrite
  338.  
  339.  cld
  340.  push     bp        ;Save base pointer
  341.  mov      bp,sp     ;Set up stack frame _before_ PaneWrite call
  342.  
  343.  call     CheckRange
  344.  jnc      win_write_0
  345.  pop      bp
  346.  ret      WWAdjust
  347.  
  348. win_write_0:
  349.  call     GetVidSeg
  350.  
  351.  cmp      WWBuffSeg,dx
  352.  jne      winw_begin
  353.  
  354.  cmp      [SnowProne],0
  355.  je       winw_begin
  356.  
  357.  call     VerticalPause
  358.  
  359. winw_begin:
  360.  mov      al,-1
  361.  call     PaneWrite ;restores ds on return
  362.  
  363.  cmp      [ShowNow],0
  364.  je       winw_leave
  365.  
  366.  cmp      WWIgnore,0     ;WWIgnore overrides ShowNow
  367.  ja       winw_leave
  368.  
  369.  call     GetVidSeg
  370.  cmp      WWBuffSeg,dx
  371.  je       winw_leave
  372.  
  373.  cmp      [SnowProne],0
  374.  je       winw_put
  375.  
  376.  call     VerticalPause
  377.  
  378. winw_put:
  379.  call     TopWinDrawLocal
  380.  
  381. winw_leave:
  382.  pop      bp
  383.  ret      WWAdjust
  384.  
  385. WinWrite  endp
  386.  
  387.  
  388. ;------------------
  389. WinPlain  proc far
  390.  
  391. ; Passes cursor coords back through ax -- see PaneWrite
  392.  
  393.  cld
  394.  push     bp        ;Save base pointer
  395.  mov      bp,sp     ;Set up stack frame _before_ PaneWrite call
  396.  
  397.  call     CheckRange
  398.  jnc      win_plain_0
  399.  pop      bp
  400.  ret      WWAdjust
  401.  
  402. win_plain_0:
  403.  call     GetVidSeg
  404.  
  405.  cmp      WWBuffSeg,dx
  406.  jne      winp_begin
  407.  
  408.  cmp      [SnowProne],0
  409.  je       winp_begin
  410.  
  411.  call     VerticalPause
  412.  
  413. winp_begin:
  414.  mov      al,0
  415.  call     PaneWrite
  416.  
  417.  cmp      [ShowNow],0
  418.  je       winp_leave
  419.  
  420.  cmp      WWIgnore,0     ;WWIgnore overrides ShowNow
  421.  ja       winp_leave
  422.  
  423.  call     GetVidSeg
  424.  cmp      WWBuffSeg,dx
  425.  je       winp_leave
  426.  
  427.  cmp      [SnowProne],0
  428.  je       winp_put
  429.  
  430.  call     VerticalPause
  431.  
  432. winp_put:
  433.  call     TopWinDrawLocal
  434.  
  435. winp_leave:
  436.  pop      bp
  437.  ret      WWAdjust
  438.  
  439. WinPlain  endp
  440.  
  441.  
  442. ;------------------
  443. WinAttr   proc far
  444.  
  445. ; Paints attribute of whole Pane based on passed parms
  446. ; Entry:  None -- BP set up for the EQU references
  447. ; Return: None
  448.  
  449. ; (Following code duplicated from PaneWrite, recast to WA equates)
  450. ; Calculate local parameters for the Pane -- Width and depth
  451.  
  452.  cld
  453.  push     bp        ;Save base pointer
  454.  mov      bp,sp     ;Set up stack frame
  455.  
  456.  mov      al,WAX4   ;Calc pane width
  457.  sub      al,WAX3
  458.  inc      al        ;Width is one more than the difference in coords
  459.  jns      wa_1      ;test: negative pane width
  460.  jmp      wa_out
  461.  
  462. wa_1:
  463.  cbw
  464.  mov      [PaneWidth],ax      ;Word-width, _not_ Byte-width!
  465.  
  466.  mov      al,WAY4
  467.  sub      al,WAY3
  468.  inc      al
  469.  jns      wa_2      ;test: negative pane depth
  470.  jmp      wa_out
  471.  
  472. wa_2:
  473.  cbw
  474.  mov      [PaneDepth],ax
  475.  
  476. ; Calculate a pointer to the Pane
  477.  
  478.  mov      ax,WABuffOff
  479.  mov      [PaneOff],ax     ;(not the final value)
  480.  
  481.  mov      al,WAWidth     ;Assume this is the Word-width of Window
  482.  xor      ah,ah
  483.  shl      ax,1            ;Double to get Byte-width
  484.  mov      [TargetIncr],ax ;Pane line separation in Window buffer
  485.  mov      bl,WAY1
  486.  dec      bl        ;X and Y are 1-based
  487.  add      bl,WAY3
  488.  dec      bl        ;X and Y are 1-based
  489.  jns      wa_3      ;test: is Y negative?
  490.  jmp      wa_out
  491.  
  492. wa_3:
  493.  mov      dl,al     ;test: is the pane within the window?
  494.  add      dl,byte ptr [PaneDepth]
  495.  cmp      dl,WAY2
  496.  jg       wa_out
  497.  mul      bl
  498.  add      [PaneOff],ax     ;Increment due to rows below top of Window
  499.  
  500.  mov      al,WAX1
  501.  dec      al        ;Since 1-based
  502.  add      al,WAX3
  503.  dec      al
  504.  js       wa_out    ;test: is X negative?
  505.  mov      dl,al     ;test: is the pane within the window
  506.  add      dl,byte ptr [PaneWidth]
  507.  cmp      dl,WAWidth
  508.  jg       wa_out
  509.  cbw
  510.  shl      ax,1      ;To get Byte-width
  511.  add      [PaneOff],ax     ;WABuffSeg:PaneOff now points to Pane top left
  512.  
  513. ; Paint the Pane
  514.  
  515.  mov      es,WABuffSeg
  516.  mov      di,[PaneOff]
  517.  mov      cx,[PaneDepth]   ;Outer loop on number of lines
  518.  
  519.  call     GetVidSeg           ;Are we repainting the video directly?
  520.  mov      ax,es
  521.  cmp      dx,ax
  522.  jne      wa_direct
  523.  call     VerticalPause
  524.  
  525. wa_direct:
  526.  mov      al,WAAttr           ;color to paint
  527.  
  528. wa_loop1:
  529.  push     cx
  530.  push     di
  531.  mov      cx,[PaneWidth]   ;Inner loop on each line
  532.  
  533. wa_loop2:
  534.  inc      di   ;position on attribute byte
  535.  stosb         ;store the new attr
  536.  loop     wa_loop2
  537.  
  538.  pop      di
  539.  add      di,[TargetIncr]
  540.  pop      cx
  541.  loop     wa_loop1
  542.  
  543.  cmp      [ShowNow],0
  544.  je       wa_out
  545.  
  546.  cmp      WAIgnore,0          ;If WAIgnore set, also override ShowNow
  547.  ja       wa_out
  548.  
  549.  call     GetVidSeg           ;Did we repaint the video directly?
  550.  mov      ax,es
  551.  cmp      dx,ax
  552.  je       wa_out
  553.  
  554.  cmp      [SnowProne],0
  555.  je       wa_put
  556.  
  557.  call     VerticalPause
  558.  
  559. wa_put:
  560.  call     TopWinDrawLocal
  561.  
  562. wa_out:
  563.  pop      bp
  564.  ret      WAAdjust  ;Adjust for parms list
  565.  
  566. WinAttr   endp
  567.  
  568.  
  569. ;------------------
  570. WinRedraw proc far
  571.  
  572. ; Transfers image of BackBuffer to video work area
  573. ; Draws all the Windows in the WinList structure to video work area
  574. ; Transfers video work area to active video page
  575.  
  576.  cld
  577.  push     bp        ;Save base pointer
  578.  mov      bp,sp     ;Set up stack frame
  579.  
  580.  mov      ax,word ptr [WinList+2] ;Segment of WinList
  581.  cmp      ax,0
  582.  je       WR_exit
  583.  
  584.  call     WinDrawLocal
  585.  
  586. WR_exit:
  587.  pop      bp
  588.  ret      WRAdjust
  589.  
  590. WinRedraw endp
  591.  
  592.  
  593. ;------------------
  594. TopWinRedraw   proc far
  595.  
  596. ; Refreshes the top window to screen, only
  597. ; Assumes no change in top window's dimensions
  598.  
  599.  cld
  600.  mov      ax,word ptr [WinList+2] ;Segment of WinList
  601.  cmp      ax,0
  602.  je       TWR_exit
  603.  
  604.  call     TopWinDrawLocal
  605.  
  606. TWR_exit:
  607.  ret
  608.  
  609. TopWinRedraw   endp
  610.  
  611.  
  612. ;------------------
  613. CheckRange     proc near
  614.  
  615. ; Checks range of variables passed to WinWrite and WinPlain
  616.  
  617.  cmp      WWX1,0
  618.  jg       ChkRange1
  619.  stc
  620.  ret
  621. ChkRange1:
  622.  cmp      WWY1,0
  623.  jg       ChkRange2
  624.  stc
  625.  ret
  626. ChkRange2:
  627.  mov      al,WWY2   ;is depth >0
  628.  sub      al,WWY1
  629.  inc      al
  630.  jns      ChkRange3
  631.  stc
  632.  ret
  633. ChkRange3:
  634.  cmp      al,WWY3   ;is start of write in range?
  635.  jge      ChkRange4
  636.  stc
  637.  ret
  638. ChkRange4:
  639.  mov      al,WWX2
  640.  cmp      al,WWWidth     ;is right side of pane in window?
  641.  jle      ChkRange5
  642.  stc
  643.  ret
  644. ChkRange5:
  645.  sub      al,WWX1
  646.  inc      al
  647.  jns      ChkRange6
  648.  stc
  649.  ret
  650. ChkRange6:
  651.  cmp      al,WWX3
  652.  jge      ChkRange7
  653.  stc
  654.  ret
  655. ChkRange7:
  656.  clc
  657.  ret
  658.  
  659. CheckRange     endp
  660.  
  661.  
  662. ;------------------
  663. TopWinDrawLocal     proc near
  664.  
  665. ; Near proc for drawing the top window
  666.  
  667.  cld
  668.  les      bx,[WinList]   ;load far pointer to top window structure
  669.  mov      ax,es
  670.  and      ax,-1
  671.  jz       twd_exit  ;make sure not zero
  672.  
  673. twd_0:
  674.  cmp      word ptr es:[bx+10],0  ;segment of next pointer
  675.  je       twd_1
  676.  les      bx,es:[bx+8]
  677.  jmp      twd_0
  678.  
  679. twd_1:
  680.  call     PutWin
  681.  
  682.  mov      dx,word ptr [FrontBuffer+2]   ;New code - 1/29/94 - restore menu/status lines
  683.  mov      ax,word ptr [FrontBuffer]
  684.  call     RestoreTopBot
  685.  
  686.  call     PutScreen
  687.  
  688. twd_exit:
  689.  ret
  690.  
  691. TopWinDrawLocal     endp
  692.  
  693.  
  694. ;------------------
  695. WinDrawLocal   proc near
  696.  
  697.  cld
  698.  call     PutBackBuffer
  699.  
  700.  les      bx,[WinList]   ;load far pointer to first window structure
  701.  
  702. wd_start:
  703.  mov      ax,es     ;Is pointer NULL
  704.  and      ax,-1
  705.  jz       wd_exit   ;WinList pointed to NULL entry
  706.  
  707.  call     PutWin
  708.  
  709.  les      bx,es:[bx+8]      ;Load the back-pointer
  710.  jmp      wd_start
  711.  
  712. wd_exit:
  713.  
  714.  mov      dx,word ptr [FrontBuffer+2]   ;New code - 1/29/94 - restore menu/status lines
  715.  mov      ax,word ptr [FrontBuffer]
  716.  call     RestoreTopBot
  717.  
  718.  cmp      WRShow,0       ;If ignore set, bypass screen put
  719.  je       wd_out
  720.  
  721.  call     PutScreen
  722.  
  723. wd_out:
  724.  ret
  725.  
  726. WinDrawLocal   endp
  727.  
  728.  
  729. ;------------------
  730. PutWin    proc near
  731.  
  732. ; Puts the window whose structure is pointed to by es:bx
  733.  
  734. ; Adjust width and depth to keep from overrunning screen edge
  735.  
  736.  cld
  737.  mov      dl,es:[bx+6] ;X coord of window, 1-based for consistency
  738.  cmp      dl,81
  739.  jl       pwinx
  740.  jmp      pwin_next
  741.  
  742. pwinx:
  743.  mov      [WinX],dl
  744.  mov      al,es:[bx+4] ;window width
  745.  xor      ah,ah
  746.  mov      [WinWidth0],ax   ;Before truncation
  747.  
  748.  shl      ax,1
  749.  mov      [SourceIncr],ax     ;how much to increment the source
  750.  shr      ax,1                ;index on each row
  751.  
  752.  add      dl,al     ;see if goes beyond right edge
  753.  sub      dl,81     ;Screen width plus 1, since 1-based
  754.  js       pwin_sto_wid     ;if sign, <screen width
  755.  sub      al,dl
  756.  
  757. pwin_sto_wid:
  758.  mov      dl,[WinX]
  759.  dec      dl
  760.  jns      pwin_sto_wid1
  761.  add      al,dl     ;add the negative X coord to the width
  762.  mov      [WinX],1
  763.  
  764. pwin_sto_wid1:
  765.  cmp      al,0
  766.  jg       pwin_sto_wid2
  767.  jmp      pwin_next
  768.  
  769. pwin_sto_wid2:
  770.  xor      ah,ah
  771.  mov      [WinWidth],ax     ;possibly truncated
  772.  
  773.  mov      dl,es:[bx+7] ;Y coord of window, 1-based
  774.  mov      [WinY],dl
  775.  cmp      dl,[ScreenLines]
  776.  jle      pwiny
  777.  jmp      pwin_next
  778.  
  779. pwiny:
  780.  mov      al,es:[bx+5] ;window depth
  781.  xor      ah,ah
  782.  mov      [WinDepth0],ax     ;before truncation
  783.  
  784.  add      dl,al
  785.  sub      dl,[ScreenLines]
  786.  dec      dl        ;since 1-based
  787.  js       pwin_sto_dep
  788.  sub      al,dl
  789.  
  790. pwin_sto_dep:
  791.  mov      dl,[WinY]
  792.  dec      dl
  793.  jns      pwin_sto_dep1
  794.  add      al,dl     ;add the negative Y coord to the depth
  795.  mov      [WinY],1
  796.  
  797. pwin_sto_dep1:
  798.  cmp      al,0
  799.  jg       pwin_sto_dep2
  800.  jmp      pwin_next
  801.  
  802. pwin_sto_dep2:
  803.  xor      ah,ah
  804.  mov      [WinDepth],ax
  805.  
  806. ; Calculate starting point in video work area for this window
  807.  
  808.  mov      al,[winY]      ;Y coord of window -- assume 1-based for consistency
  809.  dec      al
  810.  push     bx        ;save offset to window structure
  811.  mov      bl,160    ;bytes per video screen line
  812.  mul      bl
  813.  pop      bx
  814.  mov      dx,ax
  815.  mov      al,[WinX]      ;X coord -- also assume 1-based
  816.  xor      ah,ah
  817.  dec      ax
  818.  shl      ax,1      ;since 2 bytes per position
  819.  add      ax,dx     ;ax now has offset in video work area for this Window
  820.  mov      di,ax
  821.  mov      [WinOff],ax
  822.  
  823.  add      di,word ptr [FrontBuffer]  ;video work area
  824.  
  825.  mov      al,es:[bx+7]   ;Y coord -- Adjust pointer to source if needed
  826.  dec      al
  827.  js       pw_adj_source
  828.  xor      al,al
  829. pw_adj_source:
  830.  not      al
  831.  inc      al
  832.  push     bx
  833.  mov      bl,byte ptr [WinWidth0]
  834.  mul      bl
  835.  pop      bx
  836.  mov      dl,es:[bx+6]   ;X coord
  837.  dec      dl
  838.  js       pw_adj_source1
  839.  xor      dl,dl
  840. pw_adj_source1:
  841.  not      dl
  842.  inc      dl
  843.  xor      dh,dh
  844.  add      ax,dx
  845.  shl      ax,1
  846.  
  847.  push     bx        ;save far pointer to structure
  848.  push     es
  849.  
  850.  les      si,es:[bx]   ;load the far pointer to the window data area -- source set
  851.  add      si,ax
  852.  mov      cx,[WinDepth]    ;for outer loop
  853.  
  854. pwin_loop:
  855.  push     cx        ;save line counter
  856.  push     di        ;save destination index
  857.  push     si        ;save source
  858.  mov      cx,[WinWidth]
  859.  
  860. pwin_1:
  861.  push     ds
  862.  push     es
  863.  mov      es,word ptr [FrontBuffer+2]
  864.  pop      ds
  865.  rep      movsw
  866.  push     ds
  867.  pop      es
  868.  pop      ds
  869.  
  870.  pop      si
  871.  add      si,[SourceIncr]  ;next source window line
  872.  pop      di
  873.  add      di,160    ;next screen line
  874.  pop      cx
  875.  loop     pwin_loop
  876.  
  877.  
  878. ; Paint the shadows:
  879.  
  880.  pop      es        ;retrieve pointer to structure
  881.  pop      bx
  882.  push     bx
  883.  push     es
  884.  
  885.  mov      al,es:[bx+6]   ;Shading rutines want original versions of X,Y
  886.  mov      [WinX],al
  887.  mov      al,es:[bx+7]
  888.  mov      [WinY],al
  889.  
  890.  call     ShadeVert
  891.  
  892.  call     ShadeHoriz
  893.  
  894.  pop      es        ;retrieve pointer to structure
  895.  pop      bx
  896.  
  897. pwin_next:            ;get pointer to next structure
  898.  ret
  899.  
  900.  
  901. PutWin    endp
  902.  
  903.  
  904. ;------------------
  905. ShadeVert proc near
  906.  
  907. ; Shades the vertical lines in the shadow
  908.  
  909.  test     [ShadowType],4     ;is this unshadowed (ie, =4)?
  910.  jz       sv_0
  911.  ret
  912.  
  913. ; Calculate coords of shading
  914.  
  915. sv_0:
  916.  cld
  917.  mov      al,[WinY]
  918.  test     [ShadowType],2   ;top or bottom shadow?
  919.  jz       sv_1
  920.  inc      al
  921.  jmp      sv_2
  922. sv_1:
  923.  dec      al
  924. sv_2:
  925.  
  926.  mov      dl,[WinX]
  927.  test     [ShadowType],1   ;left or right shadow?
  928.  jz       sv_3
  929.  add      dl,byte ptr [WinWidth0]
  930.  jmp      sv_4
  931. sv_3:
  932.  dec      dl
  933.  dec      dl
  934. sv_4:
  935.  
  936. ; al now has shadow Y, dl shadow X
  937. ; Calculate offset of shadow
  938.  
  939.  push     ax
  940.  push     dx
  941.  
  942.  dec      al        ;because Y 1-based
  943.  cbw
  944.  mov      bx,80
  945.  push     dx
  946.  mul      bx
  947.  pop      dx
  948.  xchg     ax,dx
  949.  cbw
  950.  add      ax,dx
  951.  dec      ax        ;because X 1-based
  952.  shl      ax,1
  953.  inc      ax
  954.  mov      di,ax     ;di now has offset of attr for vertical shading 
  955.  
  956.  add      di,word ptr [FrontBuffer]  ;video work area
  957.  mov      es,word ptr [FrontBuffer+2]
  958.  
  959.  pop      dx
  960.  pop      ax   ;al has shadow Y - stack right
  961.  
  962.  mov      dh,al     ;X is in dl, and Y is in dh
  963.  mov      bl,80     ;XMax
  964.  mov      bh,[ScreenLines]   ;YMax
  965.  
  966.  mov      cx,[WinDepth0]
  967.  mov      al,[ShadowAttr]
  968.  
  969.  cmp      dl,1      ;Is X coord of shading in bounds?
  970.  jl       sv_6
  971.  cmp      dl,bl
  972.  jg       sv_6
  973.  
  974. sv_5:
  975.  push     cx
  976.  push     dx
  977.  push     di
  978.  
  979. sv_left_loop:
  980.  cmp      dh,1      ;Is Y coord in bounds?
  981.  jl       sv_left_loop1
  982.  cmp      dh,bh
  983.  jg       sv_left_loop1
  984.  stosb
  985.  jmp      sv_left_loop2
  986. sv_left_loop1:      ;bypass the attr stosb
  987.  inc      di
  988. sv_left_loop2:
  989.  add      di,159    ;position to next row
  990.  inc      dh        ;adjust dummy Y to next row
  991.  loop     sv_left_loop
  992.  
  993.  pop      di   ;Restore dest index...
  994.  pop      dx   ;coords...
  995.  pop      cx   ;and counter - stack right
  996.  
  997. sv_6:
  998.  inc      dl   ;index X to next column
  999.  inc      di   ;adjust dest ptr
  1000.  inc      di
  1001.  
  1002.  cmp      dl,1      ;Is X coord of shading in bounds?
  1003.  jl       sv_out
  1004.  cmp      dl,bl
  1005.  jg       sv_out
  1006.  
  1007. sv_rt_loop:
  1008.  cmp      dh,1      ;Is Y coord in bounds?
  1009.  jl       sv_rt_loop1
  1010.  cmp      dh,bh
  1011.  jg       sv_rt_loop1
  1012.  stosb
  1013.  jmp      sv_rt_loop2
  1014. sv_rt_loop1:      ;bypass the attr stosb
  1015.  inc      di
  1016. sv_rt_loop2:
  1017.  add      di,159    ;position to next row
  1018.  inc      dh        ;increment dummy y
  1019.  loop     sv_rt_loop
  1020.  
  1021. sv_out:
  1022.  ret
  1023.  
  1024. ShadeVert endp
  1025.  
  1026.  
  1027. ;------------------
  1028. ShadeHoriz     proc near
  1029.  
  1030. ; Shades the horizontal line in the shadow
  1031.  
  1032.  test     [ShadowType],4     ;is this unshadowed (ie, =4)?
  1033.  jz       sh_0
  1034.  ret
  1035.  
  1036. ; Calculate coords of horizontal shading
  1037.  
  1038. sh_0:
  1039.  cld
  1040.  mov      al,[WinY]
  1041.  test     [ShadowType],2   ;top or bottom shadow?
  1042.  jnz      sh_1
  1043.  dec      al
  1044.  jmp      sh_2
  1045. sh_1:
  1046.  add      al,byte ptr [WinDepth0]
  1047. sh_2:
  1048.  
  1049.  mov      dl,[WinX]
  1050.  test     [ShadowType],1   ;left or right shadow?
  1051.  jz       sh_3
  1052.  inc      dl
  1053.  inc      dl
  1054.  jmp      sh_4
  1055. sh_3:
  1056.  dec      dl
  1057.  dec      dl
  1058. sh_4:
  1059.  
  1060. ; al now has shadow Y, dl shadow X
  1061. ; Calculate offset of shadow
  1062.  
  1063.  push     ax
  1064.  push     dx
  1065.  
  1066.  dec      al        ;Since Y coord of shade is 1-based
  1067.  cbw
  1068.  mov      bx,80
  1069.  push     dx
  1070.  mul      bx
  1071.  pop      dx
  1072.  
  1073.  xchg     ax,dx
  1074.  cbw
  1075.  add      ax,dx
  1076.  dec      ax        ;Since the X coord of shade is 1-based
  1077.  shl      ax,1
  1078.  inc      ax
  1079.  mov      di,ax     ;di now has offset of attr for horizontal shading 
  1080.  
  1081.  add      di,word ptr [FrontBuffer]  ;video work area
  1082.  mov      es,word ptr [FrontBuffer+2]
  1083.  
  1084.  pop      dx
  1085.  pop      ax   ;al has shadow Y - stack right
  1086.  
  1087.  mov      dh,al     ;X is in dl and Y in dh
  1088.  mov      bl,80     ;XMax
  1089.  mov      bh,[ScreenLines]    ;YMax
  1090.  
  1091.  mov      cx,[WinWidth0]
  1092.  mov      al,[ShadowAttr]
  1093.  
  1094.  cmp      dh,1      ;Is shadow Y in bounds
  1095.  jl       sh_out
  1096.  cmp      dh,bh
  1097.  jg       sh_out
  1098.  
  1099. sh_loop:
  1100.  cmp      dl,1      ;Is shadow X in bounds?
  1101.  jl       sh_loop1
  1102.  cmp      dl,bl
  1103.  jg       sh_loop1
  1104.  stosb
  1105.  jmp      sh_loop2
  1106. sh_loop1:
  1107.  inc      di
  1108. sh_loop2:
  1109.  inc      di
  1110.  inc      dl        ;adjust dummy X to next col
  1111.  loop     sh_loop
  1112.  
  1113. sh_out:
  1114.  ret
  1115.  
  1116. ShadeHoriz     endp
  1117.  
  1118.  
  1119. ;------------------
  1120. PaneWrite proc near
  1121.  
  1122. ; Writes data from far string into Window work area "pane" defined
  1123. ;  by WWX1,WWY1 - WWX2,XXY2, starting at WWX3, WWY3
  1124. ; Entry:  al= 0, call was from WinPlain
  1125. ;           =-1, call was from WinWrite
  1126. ; Return: al=X coordinate of final cursor position relative to Pane top left
  1127. ;         ah=Y coordinate as above
  1128. ;            X,Y calculated for next position in the Pane beyond the written
  1129. ;            string, unless the right-hand edge of the pane was encountered
  1130. ;            and line wrapping was _not_ in effect, or string ended up dead
  1131. ;            against the lower right boundary of the Pane.  In these cases
  1132. ;            the cursor coords point to the last character written.
  1133.  
  1134.  cld
  1135.  mov      [PaneType],al    ;store for attribute decisions
  1136.  mov      [CRFlag],0       ;Initialize carriage return flag
  1137.  
  1138.  push     ds
  1139.  lds      si,WWStr  ;test for zero-length
  1140.  lodsb              ;length
  1141.  pop      ds
  1142.  
  1143.  cmp      al,0
  1144.  jne      pw_start
  1145.  
  1146.  mov      al,WWX3
  1147.  mov      ah,WWY3
  1148.  ret
  1149.  
  1150. pw_start:
  1151.  
  1152. ; Calculate local parameters for the Pane -- Width and depth
  1153.  
  1154.  mov      al,WWX2   ;Calc pane width
  1155.  sub      al,WWX1
  1156.  inc      al        ;Width is one more than the difference in coords
  1157.  xor      ah,ah
  1158.  mov      [PaneWidth],ax   ;Word-width, _not_ Byte-width!
  1159.  
  1160.  mov      al,WWY2
  1161.  sub      al,WWY1
  1162.  inc      al
  1163.  xor      ah,ah
  1164.  mov      [PaneDepth],ax
  1165.  
  1166. ; Calculate a pointer to the Pane
  1167.  
  1168.  mov      ax,WWBuffOff
  1169.  mov      [PaneOff],ax     ;(not the final value)
  1170.  
  1171.  mov      al,WWWidth     ;Assume this is the Word-width of Window
  1172.  shl      al,1           ;Double to get Byte-width
  1173.  xor      ah,ah
  1174.  mov      [TargetIncr],ax ;Pane line separation in Window buffer
  1175.  mov      bl,WWY1
  1176.  dec      bl        ;X and Y are 1-based
  1177.  mul      bl
  1178.  add      [PaneOff],ax     ;Increment due to rows below top of Window
  1179.  
  1180.  mov      al,WWX1
  1181.  dec      al        ;Since 1-based
  1182.  shl      al,1      ;To get Byte-width
  1183.  xor      ah,ah
  1184.  add      [PaneOff],ax     ;WWBuffSeg:PaneOff now points to Pane top left
  1185.  
  1186. ; Calculate destination pointer to start the write operation
  1187.  
  1188.  mov      es,WWBuffSeg     ;es:di point to top-left of Pane
  1189.  mov      di,[PaneOff]     ;how much to add to point to write start?
  1190.  
  1191.  mov      al,WWY3   ;1-based _local_ (relative to WWY1) coord to start write
  1192.  dec      al        ;No adjustment if on row 1
  1193.  mov      bl,byte ptr [TargetIncr] ;Number of rows deep*line index for Window
  1194.  mul      bl
  1195.  
  1196.  add      di,ax     ;Offset to left edge of Pane, on same line as write starts
  1197.  push     di        ;Save this offset for subsequent lines -- Stack +1 --
  1198.  
  1199.  mov      dl,WWX3
  1200.  dec      dl        ;Since also 1-based
  1201.  shl      dl,1      ;For Byte-offset
  1202.  xor      dh,dh
  1203.  add      di,dx     ;ax contains incremental offset from Pane corner to write
  1204.                     ;location
  1205.  
  1206. ; How many lines can we write?
  1207.  
  1208.  mov      al,byte ptr [PaneDepth]
  1209.  sub      al,WWY3   ;al has number of lines in pane below starting line
  1210.  mov      [WriteDepth],al
  1211.  
  1212. ; How many characters permitted on first line of write?
  1213.  mov      cl,byte ptr [PaneWidth]   ;Word-wise width
  1214.  xor      ch,ch     ;subsequent lines will use the full PaneWidth
  1215.  push     cx        ;save counter for subsequent lines -- Stack +2 --
  1216.  sub      cl,WWX3
  1217.  inc      cl        ;since X3 is 1-based -- no adjustment if on col 1
  1218.  
  1219.  push     ds
  1220.  lds      si,WWStr    ;Load the string pointer
  1221.  lodsb              ;string length in al
  1222.  pop      ds
  1223.  
  1224.  mov      dl,al     ;Keep separate track of string count in dl
  1225.  mov      ah,WWAttr
  1226.  mov      dh,[PaneType]    ;dh has flag whether to store WWAttr with char
  1227.  jmp      pw_loop1  ;Bypass the pushes for the line width counter counter and
  1228.                     ;destination index to Window Buffer,
  1229.                     ;since di and cx on stack already
  1230.  
  1231. pw_loop:
  1232.  push     di
  1233.  push     cx
  1234.  
  1235. pw_loop1:
  1236.  push     ds
  1237.  mov      ds,WWStrSeg
  1238.  lodsb              ;next byte of string
  1239.  pop      ds
  1240.  
  1241.  dec      dl        ;initial value of string len was _not_ zero
  1242.  cmp      al,13
  1243.  je       pw_fill_line
  1244.  cmp      al,10
  1245.  jne      pw_loop2  ;char is not delimiter.  Print and keep looping
  1246.  
  1247. ;---------  If Delimiter:  --------
  1248.  
  1249. pw_fill_line:       ;delimiter: Fill rest of line with blanks
  1250.  mov      al,32     ;blank
  1251. pw_fl_loop:         ;fill rest of line with blanks
  1252.  cmp      dh,0
  1253.  je       pw_fl_no_attr
  1254.  stosw
  1255.  jmp      pw_fl_loop_end
  1256. pw_fl_no_attr:
  1257.  stosb
  1258.  inc      di
  1259. pw_fl_loop_end:
  1260.  loop     pw_fl_loop
  1261.  
  1262.  mov      cx,1      ;Reset line counter so loop will fall through
  1263.  mov      [CRFlag],-1 ;Set the flag that says encountered CR or LF
  1264.  
  1265.  cmp      dl,0      ;was LF or CR end of string?
  1266.  je       pw_scroll_out
  1267.  
  1268.  push     ds
  1269.  mov      ds,WWStrSeg
  1270.  mov      bx,[si+0FFFFh]
  1271.  pop      ds
  1272.  
  1273.  cmp      bx,0A0Dh ;Was the CR or LF followed by a LF or CR?
  1274.  je       pw_eat_crlf
  1275.  cmp      word ptr [si+0FFFFh],0D0Ah
  1276.  jne      pw_test2  ;loop out
  1277.  
  1278. pw_eat_crlf:
  1279.  lodsb              ;eat the next char
  1280.  dec      dl        ;decrement string length counter
  1281.  cmp      dl,0      ;was the second delimiter the last char in string?
  1282.  jne      pw_test2  ;more in the string.  Fall through loop and scroll
  1283.  
  1284. pw_scroll_out:           ;line delimiter was last char of string...
  1285.  pop      cx
  1286.  pop      bx             ;stack is right for exit
  1287.  
  1288.  cmp      [WriteDepth],0   ;is there a free line below this
  1289.  ja       pw_scroll_out1
  1290.  
  1291.  cmp      [LineWrap],0
  1292.  je       pw_exit   ;if scroll off and no more lines below, leave di and exit
  1293.  
  1294. pw_scroll_out1:
  1295.  mov      di,bx
  1296.  add      di,[TargetIncr] ;Reindex the destination to next line down in window
  1297.  
  1298.  dec      [WriteDepth]     ;last line in pane?
  1299.  jns      pw_exit        ;No -  Just exit
  1300.  call     ScrollPane    ;Yes - Scroll pane and exit
  1301.  jmp      pw_exit
  1302.  
  1303. ;----------------------------
  1304.  
  1305. pw_loop2:           ;Came here is char was not delimiter
  1306.  cmp      dh,0
  1307.  je       pw_no_attr
  1308.  stosw
  1309.  jmp      pw_test
  1310. pw_no_attr:
  1311.  stosb
  1312.  inc      di        ;in place of attribute
  1313.  
  1314. pw_test:
  1315.  cmp      dl,0
  1316.  jne      pw_test2  ;more chars in string. Fall through loop and scroll
  1317.  
  1318.  pop      cx        ;End-of-string -- clear the stack...
  1319.  pop      bx        ;Leave di alone for coordinate calculation
  1320.  jmp      pw_exit   ;...and leave
  1321.  
  1322. pw_test2:
  1323.  loop     pw_loop1a ;loops to end of line in Pane
  1324.  jmp      short pw_loop1_out
  1325.  
  1326. pw_loop1a:
  1327.  jmp      pw_loop1
  1328.  
  1329. pw_loop1_out:
  1330.  pop      cx        ;end of line in Pane -- this is line byte counter
  1331.  pop      bx        ;stack is right. Leave di alone for possible coord calc
  1332.  
  1333.  cmp      [CRFlag],-1 ;If CRFlag set, overrides LineWrap off
  1334.  je       pw_test3
  1335.  
  1336.  cmp      [LineWrap],0 ;wrapping on?
  1337.  jne      pw_test3
  1338.  
  1339.  cmp      byte ptr [WriteDepth],0
  1340.  je       pw_exit   ;if no line wrapping and no line below, done
  1341.  mov      di,bx     ;if room below current line in pane, move to start of it
  1342.  add      di,[TargetIncr]
  1343.  jmp      pw_exit
  1344.  
  1345. pw_test3:                ;wrapping is on, or CR or LF encountered
  1346.  mov      [CRFlag],0  ;reset carriage return flag
  1347.  
  1348.  mov      di,bx     ;Restore di, since not exiting
  1349.  add      di,[TargetIncr] ;Reindex the destination to next line down in window
  1350.  
  1351.  dec      [WriteDepth]
  1352.  js       pw_scroll
  1353.  jmp      pw_loop
  1354.  
  1355. ; Got to bottom of pane. That means long string, line wrapping is in effect
  1356. ; Scroll the pane up a line, adjust di back to start of last line.
  1357.  
  1358. pw_scroll:
  1359.  call     ScrollPane     ;It saves all key registers
  1360.  sub      di,[TargetIncr] ;restore destination index to bottm line of Pane
  1361.  jmp      pw_loop   ;Keep doing this until string is finished
  1362.  
  1363.  
  1364. pw_exit:       ;di has the next cursor position, byte-wise, rel to Window
  1365.  mov      ax,di
  1366.  sub      ax,[PaneOff]     ;adjust to top left of Pane
  1367.  mov      bl,byte ptr [TargetIncr]      ;find coords rel to Window top left
  1368.  div      bl                  ;al will have 0-based Y, ah 0-based X
  1369.  xchg     ah,al               ;get them in the prescribed regs
  1370.  sub      al,WWX1             ;make rel to Pane top left
  1371.  sub      ah,WWY1
  1372.  add      ax,101h             ;make them 1-based
  1373.  
  1374.  cmp      al,byte ptr [PaneWidth]   ;is it past the right edge of pane?
  1375.  jbe      pw_exit2       ;if legal, exit
  1376.  cmp      [LineWrap],0     ;if wrap off, force to right edge of Pane
  1377.  jne      pw_exit3
  1378.  mov      al,byte ptr [PaneWidth]   ;force to right edge of Pane
  1379.  jmp      pw_exit2
  1380.  
  1381. pw_exit3:
  1382.  mov      al,1      ;if past right edge, force to start of next line
  1383.  inc      ah
  1384.  cmp      ah,byte ptr [PaneDepth]   ;is Y still in bounds?
  1385.  jbe      pw_exit2
  1386.  
  1387.  mov      al,byte ptr [PaneWidth]   ;the write ended at the lower right
  1388.  mov      ah,byte ptr [PaneDepth]   ;boundary of the Pane.
  1389.  
  1390. pw_exit2:
  1391.  ret
  1392.  
  1393. PaneWrite endp
  1394.  
  1395.  
  1396. ;------------------
  1397. ScrollPane     proc near
  1398.  
  1399. ; Scrolls the current pane up one line - Call only after defining Pane parms
  1400. ; Entry:  None
  1401. ; Return: None
  1402.  
  1403.  cld
  1404.  push     ds
  1405.  push     es
  1406.  push     si
  1407.  push     di
  1408.  push     dx
  1409.  push     cx
  1410.  push     ax
  1411.  
  1412.  mov      es,WWBuffSeg        ;Set up registers for the movsw loops
  1413.  
  1414.  mov      di,[PaneOff]
  1415.  mov      si,di
  1416.  add      si,[TargetIncr]
  1417.  
  1418.  mov      cx,[PaneDepth]
  1419.  dec      cx                  ;since we are moving n-1 rows, maximum
  1420.  js       sp_exit
  1421.  jz       sp_exit        ;Exit if counter negative or zero
  1422.  
  1423. sp_loop:
  1424.  push     cx
  1425.  push     si
  1426.  push     di
  1427.  
  1428.  mov      cx,[PaneWidth]
  1429.  
  1430.  push     ds
  1431.  mov      ds,WWBuffSeg        ;Set up registers for the movsw loops
  1432.  rep      movsw
  1433.  pop      ds
  1434.  
  1435.  pop      di        ;Restore the indices
  1436.  pop      si
  1437.  pop      cx
  1438.  mov      ax,[TargetIncr]
  1439.  add      si,ax     ;Increment the indices by the offset in Window buffer
  1440.  add      di,ax
  1441.  loop     sp_loop
  1442.  
  1443. sp_exit:
  1444.  mov      al,32     ;Blank the bottom line, keeping attribute
  1445.  mov      cx,[PaneWidth]
  1446.  
  1447. sp_blank_line:
  1448.  stosb
  1449.  inc      di
  1450.  loop     sp_blank_line
  1451.  
  1452.  pop      ax        ;Restore registers of interest and return
  1453.  pop      cx
  1454.  pop      dx
  1455.  pop      di
  1456.  pop      si
  1457.  pop      es
  1458.  pop      ds
  1459.  ret
  1460.  
  1461. ScrollPane     endp
  1462.  
  1463.  
  1464. ;------------------
  1465. PutScreen proc near
  1466.  
  1467. ; Writes the screen from work area to video page 0
  1468. ; Entry:  None
  1469. ; Return: None
  1470.  
  1471.  cld
  1472.  test     byte [SnowProne],1
  1473.  jz       ps1
  1474.  call     VerticalPause  ;Wait for next vertical retrace
  1475.  
  1476. ps1:
  1477.  xor      di,di
  1478.  call     GetVidSeg
  1479.  cmp      dx,0B800h
  1480.  je       ps1a
  1481.  mov      ax,[SegB000]
  1482.  jmp      short ps1b
  1483. ps1a:
  1484.  mov      ax,[SegB800]
  1485. ps1b:
  1486.  mov      es,ax
  1487.  
  1488.  mov      al,[ScreenLines]    ;Set up counter
  1489.  mov      bl,80
  1490.  
  1491.  mul      bl
  1492.  mov      cx,ax     ;Words to move
  1493.  
  1494.  push     ds        ;Set source - the video work area
  1495.  lds      si,[FrontBuffer]
  1496.  rep      movsw
  1497.  pop      ds
  1498.  
  1499.  ret
  1500.  
  1501. PutScreen endp
  1502.  
  1503.  
  1504. ;------------------
  1505. PutBackBuffer  proc near
  1506.  
  1507. ; Writes the BackBuffer to video work area
  1508. ; Entry:  None
  1509. ; Return: None
  1510.  
  1511.  cld
  1512.  mov      al,[ScreenLines]    ;Set up counter
  1513.  mov      bl,80
  1514.  mul      bl
  1515.  mov      cx,ax     ;Words to move
  1516.  
  1517.  les      di,[FrontBuffer]
  1518.  push     ds
  1519.  lds      si,[Backbuffer]
  1520.  rep      movsw
  1521.  pop      ds
  1522.  ret
  1523.  
  1524. PutBackBuffer  endp
  1525.  
  1526.  
  1527. ;------------------
  1528. RestoreTopBot  proc near
  1529.  
  1530. ; Restores top and bottom lines from BackBuffer to screen work area,
  1531. ; according to external parameters BBTop and BBBot
  1532.  
  1533. ; Entry:  dx:ax = pointer to target screen work area
  1534. ; Return: none
  1535.  
  1536.  cmp      [BBTop],0
  1537.  je       NoTopLines
  1538.  
  1539.  push     dx             ;Save target pointer
  1540.  push     ax
  1541.  
  1542.  mov      es,dx
  1543.  mov      di,ax
  1544.  mov      si,word ptr [BackBuffer]
  1545.  
  1546.  mov      al,[BBTop]     ;Calculate number of words to move
  1547.  mov      bl,80
  1548.  mul      bl
  1549.  mov      cx,ax
  1550.  
  1551.  push     ds
  1552.  mov      ds,word ptr [BackBuffer+2]
  1553.  rep
  1554.  movsw
  1555.  pop      ds
  1556.  
  1557.  pop      ax
  1558.  pop      dx
  1559.  
  1560. NoTopLines:
  1561.  cmp      [BBBot],0
  1562.  je       NoBotLines
  1563.  
  1564.  mov      es,dx
  1565.  mov      di,ax
  1566.  mov      si,word ptr [BackBuffer]
  1567.  
  1568.  mov      al,[BBBot]     ;Calculate number of words to move
  1569.  mov      bl,80
  1570.  mul      bl
  1571.  mov      cx,ax
  1572.  
  1573.  mov      al,[ScreenLines]    ;Calculate offset of first word to move
  1574.  sub      al,[BBBot]
  1575.  mov      bl,160
  1576.  mul      bl
  1577.  add      si,ax          ;Win72 incorrectly had these 2 steps as sub
  1578.  add      di,ax
  1579.  
  1580.  push     ds
  1581.  mov      ds,word ptr [BackBuffer+2]
  1582.  rep
  1583.  movsw
  1584.  pop      ds
  1585.  
  1586. NoBotLines:
  1587.  ret
  1588.  
  1589. RestoreTopBot  endp
  1590.  
  1591.  
  1592. ;------------------
  1593. GetVidSeg proc near
  1594.  
  1595. ; Finds segment of video page 0 and work area
  1596. ; Entry:  None
  1597. ; Return: Dx=VidSeg
  1598.  
  1599.  int      11h       ;Get system configuration
  1600.  mov      dx,0B800h ;VidSeg if color card
  1601.  and      al,30h    ;If mono card
  1602.  cmp      al,30h
  1603.  jne      gvs1
  1604.  mov      dx,0B000h ;Mono VidSeg
  1605.  
  1606. gvs1:
  1607.  ret
  1608.  
  1609. GetVidSeg endp
  1610.  
  1611.  
  1612. ;------------------
  1613. VerticalPause  proc near
  1614.  
  1615. ; Pauses until vertical retrace
  1616. ; Entry:  None
  1617. ; Return: None
  1618.  
  1619.  call     GetVidSeg
  1620.  mov      bx,dx     ;Video segment - If mono, looks at different port
  1621. vp0:
  1622.  mov      dx,3DAh   ;VGA Input Status #1 for color
  1623.  cmp      bx,0B800h
  1624.  je       vp1
  1625.  mov      dx,3BAh
  1626. vp1:
  1627.  in       al,dx
  1628.  test     al,8
  1629.  jz       vp0       ;Hold up if VR bit not set
  1630.  ret
  1631.  
  1632. VerticalPause  endp
  1633.  
  1634.  
  1635. ;------------------
  1636. FillVideo   proc far
  1637.  
  1638. ; Stuffs a buffer with a 2-byte sequence
  1639. ; Entry:  None -- BP set up for the EQU references
  1640. ; Return: None
  1641.  
  1642.  
  1643.  cld
  1644.  push     bp                      ;Save BP
  1645.  mov      bp,sp                   ;Set up stack frame
  1646.  push     ds                      ;Save DS
  1647.  
  1648.  les      di,FVBuffer
  1649.  mov      cx,FVLen
  1650.  mov      ax,FVData
  1651.  rep      stosw
  1652.  
  1653.  pop      ds                      ;Restore DS
  1654.  
  1655.  mov      sp,bp                   ;Restore SP -- Yo, Boboli Pizza - Thissa
  1656.                                   ;uselessa steppa, man!  You gotta keep the
  1657.                                   ;stack right, or you'll screw up ds, and if
  1658.                                   ;you've been cool and not corrupted it,
  1659.                                   ;sp's already same as bp!
  1660.  
  1661.  pop      bp                      ;Restore BP
  1662.  ret      FVAdjust
  1663.  
  1664. FillVideo    ENDP
  1665.  
  1666.  
  1667. ; ----------------
  1668. Different   proc far
  1669.  
  1670. ;    Different compares MCByteCount bytes in the arrays pointed to
  1671. ;    by MCSource and MCTarget, and returns the result of the comparison
  1672. ;    in the flags register.
  1673.  
  1674.  
  1675.  cld
  1676.  push     bp                       ;Save BP
  1677.  mov      bp,sp                    ;Set up stack frame
  1678.  push     ds                       ;Save DS
  1679.  
  1680.  mov      cx,MCByteCount           ;load the byte count
  1681.  les      di,MCTarget              ;load the target pointer is es:di
  1682.  lds      si,MCSource              ;and the source is ds:si
  1683.  repe     cmpsb                    ;compare bytewise while equal
  1684.  
  1685.  je       MCSame
  1686.  mov      ax,1
  1687.  jmp      short MCOut
  1688.  
  1689. MCSame:
  1690.  xor      ax,ax
  1691.  
  1692. MCOut:
  1693.  pop      ds
  1694.  pop      bp
  1695.  ret      MCAdjust
  1696.  
  1697. Different   endp
  1698.  
  1699.  
  1700.  
  1701. ; ----------------
  1702.  
  1703. A_________   proc far
  1704.  
  1705. ; Internal use only
  1706.  
  1707.  cld
  1708.  push     bp                       ;Save BP
  1709.  mov      bp,sp                    ;Set up stack frame
  1710.  push     ds                       ;Save DS
  1711.  
  1712.  pop      ds
  1713.  pop      bp
  1714.  ret
  1715.  
  1716. A_________   endp
  1717.  
  1718.  ENDS     CODE
  1719.  
  1720.  
  1721. END
  1722.  
  1723.  
  1724.